package com.wangmengtao.upms.service.impl;

import com.wangmengtao.upms.dto.EasyuiTree;
import com.wangmengtao.upms.util.TreeNodeUtil;
import com.wangmengtao.upms.dao.UpmsPermissionDao;
import com.wangmengtao.upms.model.UpmsPermission;
import com.wangmengtao.upms.service.UpmsPermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
/**
 * @ClassName: UpmsPermissionServiceImpl
 * @Description: TODO
 * @Author: WangMengtao
 * @Data: 2019/6/5 17:15
 * @Version: 1.0.0
 */
@Service
public class UpmsPermissionServiceImpl implements UpmsPermissionService {

    @Autowired
    private UpmsPermissionDao upmsPermissionDao;

    @Override
    public int insert(UpmsPermission upmsPermission) {
        return 0;
    }

    @Override
    public int deleteById(Long id) {
        return 0;
    }

    @Override
    public int update(UpmsPermission upmsPermission) {
        return upmsPermissionDao.update(upmsPermission);
    }

    @Override
    public int deleteByIds(List<Long> ids) {
        return 0;
    }

    @Override
    public UpmsPermission getById(Long id) {
        return upmsPermissionDao.getById(id);
    }

    @Override
    public List<UpmsPermission> list() {
        return upmsPermissionDao.list();
    }

    @Override
    public List<UpmsPermission> listByParentId(Long parentId) {
        return upmsPermissionDao.listByParentId(parentId);
    }

    @Override
    public List<EasyuiTree> tree() {
        List<EasyuiTree> easyuiTrees = new ArrayList<EasyuiTree>();
        List<UpmsPermission> upmsPermissions = this.list();
        if (upmsPermissions == null) {
            return easyuiTrees;
        }
        for (UpmsPermission upmsPermission : upmsPermissions) {
            EasyuiTree easyuiTree = new EasyuiTree();
            easyuiTree.setId(upmsPermission.getId());
            easyuiTree.setText(upmsPermission.getName());
            easyuiTree.setIconCls(upmsPermission.getIcon());
            easyuiTree.setUrl(upmsPermission.getUrl());
            easyuiTree.setParentId(upmsPermission.getParentId());
            easyuiTrees.add(easyuiTree);
        }
        return TreeNodeUtil.getFatherNode(easyuiTrees);
    }
}
